﻿using HrEFCore.Models;
using HrService;
using HrUI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Net.NetworkInformation;

namespace HrUI.Controllers
{
    public class HomeController : Controller
    {
		private readonly ILogger<HomeController> _logger;
		private readonly UserService userService;
		private readonly RolesService rolesService;
		private readonly IHttpContextAccessor httpContextAccessor;

		public HomeController(ILogger<HomeController> logger, UserService userService, RolesService rolesService, IHttpContextAccessor httpContextAccessor)
		{
			_logger = logger;
			this.userService = userService;
			this.rolesService = rolesService;
			this.httpContextAccessor = httpContextAccessor;
		}

		public IActionResult Index()
        {
            return View();
        }
		public async Task<IActionResult> LefeMenu(short rid)
		{
			List<Menu> menus = rolesService.SelectMenuById(rid);
			return Json(menus);
		}
		public string GenerateUrl(string s)
		{
			string url = Url.Content("~" + s); // 使用Url.Content方法生成相对路径的URL
			return url;
		}
		public IActionResult main()
		{
			return View();
		}
		public IActionResult top()
		{
			return View();
		}
		public IActionResult left()
		{
			int getRolesID = httpContextAccessor.HttpContext.Session.GetInt32("getRolesID") ?? 0;
			ViewData["getRolesID"] = getRolesID;
			return View();
		}
		public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}